<template>
  <LayoutContainer>
    <UiLoadingPanel v-if="pending" />
    <div v-else>
      <h2>EducationTiming</h2>
      <UiForm
        ref="form"
        :model="EducationTiming"
        :entity="education_timings"
        :submitActions="submitActions"
      >
        <UiInputNumber
          field="educationtiming"
          v-model="education_timings.timing"
          :rules="rules"
        />
      </UiForm>
    </div>
  </LayoutContainer>
</template>
<script setup lang="ts">
import { ref, computed } from 'vue'
import { useEntityFetch } from '~/composables/data/useEntityFetch'
import EducationTiming from '~/models/Education/EducationTiming'
import { useRoute } from 'vue-router'
import { useI18n } from 'vue-i18n'
import { AnyJson } from '~/types/data'
import { SUBMIT_TYPE } from '~/types/enum/enums'

const i18n = useI18n()
const { fetch } = useEntityFetch()
const route = useRoute()
const idValue = Array.isArray(route.params.id)
  ? route.params.id[0]
  : route.params.id
const educationTimingID = ref(parseInt(idValue))

const goBackRoute = { path: `/parameters`, query: { tab: 'educationTimings' } }

const submitActions = computed(() => {
  let actions: AnyJson = {}
  actions[SUBMIT_TYPE.SAVE_AND_BACK] = goBackRoute
  return actions
})

const { data: education_timings, pending } = fetch(
  EducationTiming,
  educationTimingID.value
)
console.log(education_timings)

const rules = () => [
  (timing: string | null) =>
    (timing !== null && timing.length > 0) || i18n.t('please_enter_a_value'),
]
</script>
